#include "sequenceviewer.h"
#include "ui_sequenceviewer.h"
#include "aso_middle_layer.h"
#include <QFileInfo>

SequenceViewer::SequenceViewer(QWidget* parent) :
    QDialog(parent),
    seqWindow(new Ui::SequenceViewer)
{
    seqWindow->setupUi(this);
    connect(seqWindow->btnClose, SIGNAL(clicked()), this, SLOT(close()));
}

SequenceViewer::~SequenceViewer()
{
    delete seqWindow;
}

void SequenceViewer::loadSequenceView(const QString& file)
{
    QFile seqFile(file);
    if (seqFile.open(QIODevice::ReadOnly))
        seqWindow->txtNucSequence->setPlainText(seqFile.readAll());

    biopp::PseudoNucSequence nucSequence;
    biopp::AminoSequence aminoSequence;

    load_sequence(qtTostdString(file), nucSequence);
    //nucSequence.translate(aminoSequence);

    QString aminos;

    for (unsigned int i = 0; i < aminoSequence.size(); ++i)
    {
        aminos += aminoSequence[i].as_char();
    }
    seqWindow->txtAminoSequence->setPlainText(aminos);
}

void SequenceViewer::showSequenceWindow()
{
    this->exec();
}


void SequenceViewer::changeEvent(QEvent* e)
{
    QDialog::changeEvent(e);
    switch (e->type())
    {
        case QEvent::LanguageChange:
            seqWindow->retranslateUi(this);
            break;
        default:
            break;
    }
}
